﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;
using NivalisEngine.Input;
using NivalisEngine;

namespace Shooter
{
    class StartMenuState: IGameObject
    {
        Renderer _renderer = new Renderer();
        Text _title;
        NivalisEngine.Font _generalFont;
        Input _input;
        VerticalMenu _menu;
        StateSystem _system;

        public StartMenuState(NivalisEngine.Font titleFont, NivalisEngine.Font generalFont, Input input, StateSystem system)
        {
            _generalFont = generalFont;
            _input = input;
            _system = system;
            InitializeMenu();
            _title = new Text("Shooter", titleFont);
            _title.SetColor(new Color(0, 0, 0, 1));
            _title.SetPosition(-_title.Width / 2, 300);
        }

        private void InitializeMenu()
        {
            _menu = new VerticalMenu(0, 150, _input);
            Button startGame = new Button(
                delegate(object o, EventArgs e)
                {
                    _system.ChangeState("inner_game");
                },
                new Text("Start", _generalFont));
            Button exitGame = new Button(
                delegate(object o, EventArgs e)
                {
                    System.Windows.Forms.Application.Exit();
                },
                new Text("Exit", _generalFont));
            _menu.AddButon(startGame);
            _menu.AddButon(exitGame);
        }


        #region IGameObject Members
        public void Update(double elapsedTime)
        {
            _menu.HandleInput();
        }

        public void Render()
        {
            Gl.glClearColor(1, 1, 1, 0);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            _renderer.DrawText(_title);
            _menu.Render(_renderer);
            _renderer.Render();
        }
        #endregion
    }
}
